package 代码记录.指定公司代码练习记录.华为_2024.分值200;

import java.util.*;

/**
 * @author zx
 * @create 2024-02-16 14:47
 * 自己的思路，用一个boolean型的数组做出来这道题
 */
public class 会议室占用时间_24 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String s1 = str.replaceAll("\\[", "");
        String s2 = s1.replaceAll("\\]", "");
        String[] temp = s2.split(",");
        int[] array = Arrays.stream(temp).mapToInt(Integer::parseInt).toArray();
        int[][] arr = new int[array.length / 2][2];
        for(int i = 0,j = 0;i < array.length;j++){
            arr[j][0] = array[i++];
            arr[j][1] = array[i++];
        }
        boolean[] ting = new boolean[101];//题意规定会议室个数范围：[1,100]
        for(int i = 0;i < arr.length;i++){
            int a = arr[i][0];
            int b = arr[i][1];
            for(int j = a;j <= b;j++){
                ting[j] = true;
            }
        }
        List<int[]> list = new ArrayList<>();
        int start = 0;
        int end = 0;
        for(int i = 0;i < ting.length;i++){
            if(ting[i] == true && start == 0){
                start = i;
            }
            if(start > 0 && end == 0 && ting[i] == true){
                continue;
            }
            if(start > 0 && end == 0 && ting[i] == false){
                end = i - 1;
                list.add(new int[]{start, end});
                start = 0;
                end = 0;
            }
        }
        StringBuilder res = new StringBuilder();
        res.append('[');
        for (int[] i : list) {
            res.append(Arrays.toString(i));
        }
        res.append(']');
        System.out.println(res);
    }
}
